package com.briup.smart.impl.client;

import com.briup.smart.env.client.Client;
import com.briup.smart.env.entity.Environment;

import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.Collection;

public class ClientImpl implements Client {
    @Override
    public void send(Collection<Environment> collection) throws Exception {

        String ip = "localhost";
        int port = 8888;
        Socket socket = new Socket(ip, port);
        System.out.println("客户端正在连接...");
        // 思考，使用什么流来发送集合？对象流、输出流
        ObjectOutputStream oos = new ObjectOutputStream(
                        socket.getOutputStream());
        oos.writeObject(collection);
        System.out.println("数据已经发送，本次共发送"+collection.size()+"条数据");
        oos.close();
        socket.close();
    }
}
